{
	template:`
	<a-page-header :title="title" :sub-title="subTitle">
		<template #extra>
		    <a-button v-if="tempPath" type="default" @click="openTempPath">下载模板</a-button>
		    <m-back @click="closeThis">关闭</m-back>
		</template>
		<a-card :hoverable="true">
            <a-alert v-if="alertMessage" message="导入提醒" show-icon :description="alertMessage" type="warning" style="margin-bottom:18px;"></a-alert>
		    <a-row type="flex" gutter="16">
		        <a-col flex="auto">
		            <a-alert v-for="item in updataList" type="success" :message="'上传：'+item.name" style="margin-top:-4px;width:410px;"></a-alert>
                    <a-alert v-if="resultType&&updataList.length==0" :type="resultType" :message="resultType=='success'?'上传成功':'上传失败'" style="margin-top:-4px;width:410px;"></a-alert>
                    <a-alert v-else-if="updataList.length==0" message="请选择要上传的Execl文件" style="margin-top:-4px;width:410px;"></a-alert>
		        </a-col>
		        <a-col flex="200px" class="text-center">
		            <a-space>
                        <a-upload :show-upload-list="false" accept=".xls,.xlsx" v-model:file-list="updataList" :beforeUpload="()=>{return false;}" @change="uploadChange" :multiple="false">
                            <a-button :type="updataList.length==0?'primary':'default'" :disabled="loadShow">{{updataList.length==0?'选择':'重新选择'}}</a-button>
                        </a-upload>
                        <a-button type="primary" :loading="loadShow" :disabled="loadShow||updataList.length==0" @click="uploadFile">上传</a-button>
		            </a-space>
		        </a-col>
		    </a-row>
		    <div v-if="loadShow" class="text-center padding-top">
		        <div v-if="progress.import=='Y'">
		            {{progress.start}} {{progress.title}}；
		            <span v-if="progress.count">{{proShow.showCurrent}}/{{progress.count}}</span>
                    <span v-if="canStop" class="padding-left">
                        <a-popconfirm title="确定要中止导入吗？" @confirm="stopImportRequest">
                            <a-typography-link>中止导入</a-typography-link>
                        </a-popconfirm>
                    </span>
		        </div>
		        <div v-else>上传中，请等待返回结果。</div>
		        <a-progress v-if="progress.count" :percent="Math.round(proShow.showCurrent/progress.count*1000)/10" :stroke-color="{'0%': 'var(--colorPrimary)','100%': 'var(--colorSuccess)',}"/>
		    </div>
		    <div v-else class="padding-top-sm"></div>
            <div v-if="resultType!='success'&&resultList.length" class="text-center">
                已发现导入错误！
                <span v-if="autoSubmit">本次完成后，成功的行无需再次导入。</span>
                <span v-else>本次导入将回滚，请修改错误的行后再次导入。</span>
            </div>
		    <div style="max-height:350px;overflow:auto;">
                <div v-for="item in resultList" class="padding-top-xs">{{item}}</div>
            </div>
		</a-card>
	</a-page-header>
	`,
	props: ['localeZh','param','parentVue'],
	data:function(){
		return {
			title:'',
			subTitle:'',
			alertMessage:'',
			action:'',
			importParam:'',
			updataList:[],
			progress:{},
			proShow:{showCurrent:0,showAdd:0},
			proTimer:null,
			proLast:0,
			proKeep:true,
			loadShow:false,
			tempPath:'',
			tempName:'',
			tempType:'download',
			resultList:[],
			resultType:'',
			canStop:false,
			autoSubmit:false
		};
	},
	mounted(){
		this.title=this.param.title||'上传Execl';
		this.action=this.param.action;
		this.importParam=this.param.importParam||'';
        this.requestData(this.action+'/getImportExcelSetting',
            {importParam:this.importParam},
            function(json){
                if(json.importParam) this.importParam=json.importParam;
                if(json.tempPath) this.tempPath=json.tempPath;
                if(json.tempName) this.tempName=json.tempName;
                if(json.tempType) this.tempType=json.tempType;
                if(json.title) this.title=json.title;
                if(json.subTitle) this.subTitle=json.subTitle;
                if(json.alertMessage) this.alertMessage=json.alertMessage;
                if(json.canStop) this.canStop=json.canStop;
                if(json.autoSubmit) this.autoSubmit=json.autoSubmit;
                //获取上传状态
                this.uploadProgress(false);
            }.bind(this)
        );
	},
	methods:{
	    openTempPath:function(){
	        if(this.tempType=="page"){
		        this.openPage(this.tempPath,{},function(){},"1000px");
            }else if(this.tempType=="open"){
                window.open(this.tempPath);
            }else if(this.tempType=="download"){
                axios.post(this.tempPath,{},{responseType: 'blob'})
                .then(function(res){
                    var blob = res.data;
                    // FileReader主要用于将文件内容读入内存
                    var reader = new FileReader();
                    reader.readAsDataURL(blob);
                    // onload当读取操作成功完成时调用
                    reader.onload = function(e) {
                        var a = document.createElement('a');
                        a.download = this.tempName?this.tempName:this.tempPath.substring(this.tempPath.lastIndexOf('/')+1);
                        a.href = e.target.result;
                        document.body.appendChild(a);
                        a.click();
                        document.body.removeChild(a);
                    }.bind(this);
                }.bind(this));
	        }
	    },
		uploadChange:function(obj){
		    if(this.updataList.length>1){
		        this.updataList=[this.updataList[1]];
		    }
        },
        uploadFile:function(){
            this.loadShow=true;
            this.resultList=[];
			var forms = new FormData();
            var configs = {
                headers:{'Content-Type':'multipart/form-data'}
            };
            forms.append('file',this.updataList[0].originFileObj);
            axios.post(this.action+'/importExcel?importParam='+this.importParam,forms ,configs)
            .then(res=>{
                if(res.data.code==0){
                    this.uploadProgress(true);
                }else{
                    this.setResultMsg(error,res.data.msg);
                }
            })
            .catch((error)=>{
                this.setResultMsg('error',error+"");
            });
		},
		stopImportRequest:function(){
            this.requestData(this.action+'/stopImportProgress',{},()=>{});
		},
		setResultList:function(msg){
            this.resultList=msg.split("\r\n");
		},
		setResultMsg:function(type,msg){
            this.resultType=type;
            this.setResultList(msg);
            this.updataList=[];
            this.loadShow=false;
            this.requestData(this.action+'/clearImportProgress',{},()=>{});
		},
		closeThis:function(){
		    this.stopProgress();
		    this.back(false);
		},
		stopProgress:function(){
            if(this.proTimer) clearTimeout(this.proTimer);
            this.proKeep=false;
		},
		uploadProgress:function(noMark){
		    var t=new Date().getTime();
		    if(t - this.proLast<1800){
                this.proTimer=setTimeout(()=>{
                    this.uploadProgress(true);
                },400);
                return;
		    }
		    this.proLast=t;
            this.requestData(this.action+'/getImportProgress',{},
                function(json){
                    this.progress=json;
                    if(json.import=='Y'){
                        this.loadShow=true;
                        if(this.proKeep){
                            if(!noMark){
                                this.proShow.showCurrent=this.progress.current;
                                this.proTimer=setTimeout(()=>{
                                    this.uploadProgress(true);
                                },1800);
                            }else if(this.progress.count&&this.progress.current){
                                this.proShow.showAdd=parseInt((this.progress.current - this.proShow.showCurrent)/5)||1;
                                this.showProgress();
                            }else{
                                this.proTimer=setTimeout(()=>{
                                    this.uploadProgress(true);
                                },2000);
                            }
                        }
                        if(json.message) this.setResultList(json.message);
                    }else if(json.import=='N'){
                        this.setResultMsg('error',json.title+"；导入失败：\r\n"+json.message);
                    }else if(json.message){
                        this.setBack(true);
                        this.setResultMsg('success',json.title+"；导入成功：\r\n"+json.message);
                    }
                }.bind(this),noMark
            );
		},
		showProgress:function(){
            this.proTimer=setTimeout(()=>{
                if(this.proShow.showCurrent&&this.proShow.showCurrent+this.proShow.showAdd>=this.progress.current){
                    this.proShow.showCurrent=this.progress.current;
                    this.uploadProgress(true);
                }else{
                    this.proShow.showCurrent+=this.proShow.showAdd;
                    this.showProgress();
                }
            },400);
		}
	}
}